fs = require('fs'),
paths = require('path'),
util = require('util'),


foldors = new Array();
filesarray = new Array();
path = 'E:/test/myfile';
console.log('准备开始');




function testfor1(){
	foldors.push({index:'1',path:"123"});
	foldors.push({index:'2',path:"234"});
	foldors.push({index:'3',path:"345"});
}
testfor1()
console.log('执行完成');
console.log('输出函数：');
for(var n = 0 ; n<foldors.length;n++){
	if(foldors[n].index==1){
		console.log(foldors[n]);
	}
}
foldors.splice(0,foldors.length);
console.log("数组内容为："+foldors+"。");



function tofoldor(callback,path){
	fs.readdir(path, function(err, files){
		if(err){console.log(err); return;}//若有错误则在控制台显示错误
		var filenum = 0;
		files.forEach( function (file){
			fs.stat(path+'/'+file,function(err,statinfo){
				if(err){console.log(err); return;}//若有错误则在控制台显示错误
				if(!statinfo.isDirectory()){
                    //console.log("file:"+file); 
                    //pcontent +="<li>"+fileone+"</li>\n";
                    filesarray.push({index:'3',path:"345"})
                }
                else{
                    
                    console.log(path+'/'+file); 
                    callback(callback,path+'/'+file);
                }
			});
		});

	});






	    //path = 'E:/test/myfile';
     fs.readdir(path, function(err, files){
        if(err){console.log(err); return;}//若有错误则在控制台显示错误
        
        files.forEach( function (file) {
            fs.stat(path+'/'+file,function(err,statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                    //console.log("file:"+file); 
                    pcontent +="<li>"+fileone+"</li>\n";
                }
                else{
                    
                    console.log(path+'/'+file); 
                    callback(callback,path+'/'+file);
                }
            });            
        });

        var fileone;
        for(var n = 0 ; n<files.length ; n++){
            fileone = files[n];
            fs.stat(path+'/'+fileone,function(err,statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                    //console.log("file:"+fileone); 
                    pcontent +="<li>"+fileone+"</li>\n";
                }
                else{
                    //console.log(path+'/'+fileone); 
                    //callback(callback,path+'/'+fileone);
                    foldornumber++;
                    foldors[foldornumber-1]=path+'/'+fileone;
                }
            });
        }

        files.forEach( function (file) {
            fs.stat(path+'/'+file,function(err,statinfo){
                if(err){console.log(err); return;}
                if(!statinfo.isDirectory()){
                    console.log("file:"+file); 
                }
                else{
                    console.log(path+'/'+file); 
                    callback(callback,path+'/'+file);
                }
            });            
        });

     });
    if(foldornumber)
    callback(callback,path+'/'+fileone);
}